package org.pzy.java.sort;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

/**
 * @Author: DRevelation
 * @Date: 2022/9/19 11:25
 */
public class MultiSort {


    public static void main(String[] args) {
        Person p1 = new Person(2, "b", new Date());
        Person p2 = new Person(1, "c", new Date());
        Person p3 = new Person(3, null, new Date());
        Person p4 = new Person(null, "b", new Date());

        List<Person> ps = new ArrayList<>();
        ps.add(p1);
        ps.add(p2);
        ps.add(p3);
        ps.add(p4);

//        ps.sort((o1, o2) -> {
//            if (o1.getName().compareTo(o2.getName()) ==0) {
//                return o1.getId().compareTo(o2.getId());
//            }
//            return o1.getName().compareTo(o2.getName());
//        });

        ps.sort(Comparator.nullsLast(Comparator.comparing(Person::getName, Comparator.nullsLast(Comparator.comparing(e -> e)))
                .thenComparing(Person::getId, Comparator.nullsFirst(Comparator.comparing(e -> e)))
                .thenComparing(Person::getId, Comparator.reverseOrder())));
        ps.forEach(System.out::println);
    }
}
